//Url building documentation is from here: http://en.gravatar.com/site/implement/url

using System.Collections;
using AndyPike.Commons.Web.MonoRail.Helpers;
using Castle.MonoRail.Framework.Test;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace AndyPike.Commons.Tests.Unit.Web.MonoRail.Helpers
{
    [TestFixture]
    public class When_using_the_gravatar_helper
    {
        private GravatarHelper helper;
        private readonly IDictionary parameters = new Hashtable { { "size", "48" }, { "default", "http://example.com/images/example.jpg" }, { "rating", "g" } };
        private const string EMAIL = " iHaveAn@email.com ";

        [SetUp]
        public void SetUp()
        {
            helper = new GravatarHelper {ServerUtility = new StubServerUtility()};
        }

        [Test]
        public void Should_build_a_basic_image_url()
        {
            string url = helper.Url(EMAIL);

            Assert.That(url, Is.EqualTo("http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802.jpg"));
        }

        [Test]
        public void Should_build_a_basic_image_url_inside_an_image_tag()
        {
            string tag = helper.Image(EMAIL);

            Assert.That(tag, Is.EqualTo("<img src=\"http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802.jpg\" alt=\"Gravatar\" />"));
        }

        [Test]
        public void Should_build_a_url_with_parameters_dictionary()
        {
            string url = helper.Url(EMAIL, parameters);

            Assert.That(url, Is.EqualTo("http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802.jpg?size=48&default=http%3a%2f%2fexample.com%2fimages%2fexample.jpg&rating=g"));
        }

        [Test]
        public void Should_build_an_image_url_inside_an_image_tag_with_parameters_dictionary()
        {
            string tag = helper.Image(EMAIL, parameters);

            Assert.That(tag, Is.EqualTo("<img src=\"http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802.jpg?size=48&default=http%3a%2f%2fexample.com%2fimages%2fexample.jpg&rating=g\" alt=\"Gravatar\" />"));
        }

        [Test]
        public void Should_build_an_image_url_inside_an_image_tag_with_parameters()
        {
            string tag = helper.Image(EMAIL, 48, "g", "http://example.com/images/example.jpg");

            Assert.That(tag, Is.EqualTo("<img src=\"http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802.jpg?size=48&default=http%3a%2f%2fexample.com%2fimages%2fexample.jpg&rating=g\" alt=\"Gravatar\" />"));
        }
    }
}